<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
cfc('core')->checklogin();
$return=array();
if($_RQ['op']=='main'){
	$return['setting']=$this->plugin_setting('basic');
	$return['list']=array();
	set_html('title','服务评论');
	exi($return);
}
if($_RQ['op']=='commentorder'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('订单不存在，请重新选择订单','error');
	}	
	$order=pdo_get('jy_jcfuwu_order',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	$order['orderid']=$id;
	$order=$this->model('model')->getorder($order);
	//用户信息
	$member=$order['member'];
	//技师
	$worker=pdo_get('jy_wxshifu_member',array('uniacid'=>$_SESSION['uniacid'],'id'=>$order['shifuid']));	
	$worker['headimg']=tomedia($worker['headimg']);
	$worker['ordersum']=pdo_count('jy_jcfuwu_order',array('uniacid'=>$_SESSION['uniacid'],'shifuid'=>$order['shifuid']));
	$serve=pdo_get('jy_jcfuwu_list',array('id'=>$order['pid'],'uniacid'=>$_SESSION['uniacid']));
	$order['serve_time']=date('Y-m-d H:i',$order['serve_time']);
	$order['serve_title']=$serve['title'];
	$order['serve_image']=$serve['image'];
	$order['serve_image']=tomedia($order['serve_image']);
	$return['order']=$order;
	$return['member']=$member;
	$return['worker']=$worker;
	$return['fileds']=$fileds;
	$comment=pdo_get('jy_jcfuwu_comment',array('uniacid'=>$_SESSION['uniacid'],'order_id'=>$order['id']));
	if($comment['id']){
		$return['isping']=1;
	}
	$return['post']=$comment?:array('star'=>5,'order_id'=>$order['id'],'pid'=>$serve['id'],'worker_id'=>$worker['id']);
	$return['post']['images']=$return['post']['images']?json_decode($return['post']['images'],true):array();
	exi($return);
}

if($_RQ['op']=='submit'){
	$postdata=get_postdata();
	$data=array(
		'msg'=>$postdata['msg'],
		'images'=>ijson_encode($postdata['images']),
		'star'=>intval($postdata['star']),
	);
	$comment_id=$this->pdo_getcolumn('comment',array('order_id'=>intval($postdata['order_id']),'pid'=>intval($postdata['pid'])),'id');
	$basic=$this->plugin_setting('basic');
	$show=$basic['shenhe']?0:1;
	if($comment_id){
		$this->pdo_update('comment',$data,array('id'=>$comment_id));
	}else{
		$insert=array(
			'uniacid'=>$_SESSION['uniacid'],
			'mid'=>$_SESSION['uid'],
			'show'=>$show,
			'pid'=>intval($postdata['pid']),
			'worker_id'=>intval($postdata['worker_id']),
			'order_id'=>intval($postdata['order_id']),
			'createtime'=>TIMESTAMP,
		);
		$data=array_merge($insert,$data);
		$this->pdo_insert('comment',$data);
		$this->update('order',array('iscomment'=>1),array('id'=>$insert['order_id'],'uniacid'=>$_SESSION['uniacid']));
	}
	$data['content']=$data['msg'];
	$data['orderid']=$data['order_id'];
	$data['shifuid']=$data['worker_id'];
	model('jy_wxshifu/member')->setcomment($data);
	exi('评价成功！','','/fuwu.order/');
}
?>